import request from "@/utils/request"
import {AxiosPromise} from "axios";
import {DeleteDTO, RecordForm, RecordInfo, RecordQuery, RecordRecommend, RecordSearch} from "./types";
import {PageQuery, Result, TableDataInfo} from "@/model";

/**
 * 查看记录列表
 * @param params 查询条件
 * @returns 记录列表
 */
export function getRecordList(params: RecordQuery): AxiosPromise<TableDataInfo> {
    return request({
        url: "/record/list",
        method: "get",
        params,
    });
}

/**
 * 查看记录
 * @param recordId 记录id
 * @returns 记录列表
 */
export function getRecordHomeById(recordId: number): AxiosPromise<Result<RecordInfo>> {
    return request({
        url: `/record/${recordId}`,
        method: "get",
    });
}

/**
 * 查看记录总览
 * @returns 记录总览列表
 */
export function getRecordOverviewList(): AxiosPromise<TableDataInfo> {
    return request({
        url: "/record/overview/list",
        method: "get",
    });
}

/**
 * 查看推荐记录
 * @returns 推荐记录
 */
export function getRecordRecommend(): AxiosPromise<Result<RecordRecommend[]>> {
    return request({
        url: "/record/recommend",
        method: "get",
    });
}

/**
 * 搜索记录
 * @returns 记录列表
 */
export function searchRecord(keyword: string): AxiosPromise<Result<RecordSearch[]>> {
    return request({
        url: "/record/search",
        method: "get",
        params: {
            keyword,
        },
    });
}

/**
 * 点赞记录
 * @param recordId 记录id
 */
export function likeRecord(recordId: number): AxiosPromise<Result<null>> {
    return request({
        url: `/record/${recordId}/like`,
        method: "post",
    });
}

/**
 * 收藏记录
 * @param recordId 记录id
 */
export function collectRecord(recordId: number): AxiosPromise<Result<null>> {
    return request({
        url: `/record/${recordId}/collect`,
        method: "post",
    });
}

/**
 * 添加记录
 * @param data 记录信息
 */
export function addRecord(data: RecordForm): AxiosPromise<Result<null>> {
    return request({
        url: "/record/add",
        method: "post",
        data,
    });
}

/**
 * 回收或恢复记录
 * @param data 逻辑删除
 */
export function recycleRecord(data: DeleteDTO): AxiosPromise<Result<null>> {
    return request({
        url: "/record/recycle",
        method: "put",
        data,
    });
}

/**
 * 修改记录
 * @param data 记录信息
 */
export function updateRecord(data: RecordForm): AxiosPromise<Result<null>> {
    return request({
        url: "/record/update",
        method: "put",
        data,
    });
}

/**
 * 编辑记录
 * @param recordId 记录id
 */
export function editRecord(recordId: number): AxiosPromise<Result<RecordForm>> {
    return request({
        url: `/record/edit/${recordId}`,
        method: "get",
    });
}

/**
 * 上传记录图片
 * @returns 图片链接
 */
export function uploadRecordImages(data: FormData): AxiosPromise<Result<string>> {
    return request({
        url: "/recordImage/upload",
        headers: { "content-type": "multipart/form-data" },
        method: "post",
        data,
    });
}

/**
 * 上传记录视频
 * @returns 视频链接
 */
export function uploadRecordVideo(data: FormData): AxiosPromise<Result<string>> {
    return request({
        url: "/recordVideo/upload",
        headers: { "content-type": "multipart/form-data" },
        method: "post",
        data,
    });
}